package ${pkg}.bean.io.${name};

import com.kool.core.base.BaseBean;
import com.kool.core.exception.AppException;
import com.kool.core.util.StringUtils;
import com.kool.core.validate.IIoValidate;

/**
 * @AUTHOR LUYU
 */
public class ${ioName}Bean extends BaseBean implements IIoValidate {
	<#list ioFields as field>
	protected String ${field.lowJavaName};
	</#list>

	<#list ioFields as field>
	public String get${field.upJavaName}() {
		return ${field.lowJavaName};
	}

	public void set${field.upJavaName}(String ${field.lowJavaName}) {
		this.${field.lowJavaName} = ${field.lowJavaName};
	}

	</#list>
	@Override
	public void validate() throws AppException {
	<#list ioFields as field>
		<#if field.nullable ?? && field.nullable == "N">
		// 非空校验
		if (StringUtils.isEmpty(${field.lowJavaName})) {
			throw new AppException("SY000036","${field.lowJavaName}");//字段[%1]为空
		}
		</#if>
		<#if field.minLen ?? && (field.minLen > 0)>
		// 最小长度校验
		if (${field.lowJavaName} != null && ${field.lowJavaName}.length() < ${field.minLen}) {
			throw new AppException("SY000037","${field.lowJavaName}",String.valueOf(${field.minLen}));//字段[%1]小于最小长度[%2]
		}
		</#if>
		<#if field.maxLen ?? && (field.maxLen > 0)>
		// 最大长度校验
		if (${field.lowJavaName} != null && ${field.lowJavaName}.length() > ${field.maxLen}) {
			throw new AppException("SY000038","${field.lowJavaName}",String.valueOf(${field.maxLen}));//字段[%1]大于最大长度[%2]
		}
		</#if>
		<#if field.min ?? && (field.min > 0) && field.javaType == "Integer">
		// 最小值校验
		if (${field.lowJavaName} != null && ${field.lowJavaName} < ${field.min}) {
			throw new AppException("SY000039","${field.lowJavaName}",String.valueOf(${field.min}));//字段[%1]小于最小值[%2]
		}
		</#if>
		<#if field.max ?? && (field.max > 0) && field.javaType == "Integer">
		// 最大值校验
		if (${field.lowJavaName} != null && ${field.lowJavaName} > ${field.max}) {
			throw new AppException("SY000040", "${field.lowJavaName}", String.valueOf(${field.max}));// 字段[%1]大于最大值[%2]
		}
		</#if>
	</#list>
	}
}